package org.example.ctsbocc.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        System.out.println("CORS 配置已启用");
        // 允许所有接口
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600);
//        // 验证码接口专用配置
//        registry.addMapping("/api/verificationCode/**")
//                .allowedOriginPatterns("*")
//                .allowedMethods("GET", "POST", "OPTIONS")
//                .allowedHeaders("*")
//                .allowCredentials(false)  // 验证码通常不需要凭证
//                .maxAge(3600);
    }
}
